﻿///////////////////////////////////////////////////////////////////////////////////////////////
// System.Text.Parsing - © 2011 Sebastien Pellizzari
// Released under the MIT License (http://www.opensource.org/licenses/mit-license.php)
///////////////////////////////////////////////////////////////////////////////////////////////
using System.Collections.Generic;

namespace System.Text.Parsing
{
    /// <summary>Represents a token group definition in a grammar.</summary>
    public sealed class GrammarTokenGroup
    {
        private readonly GrammarTextValue _name;                    // Group name.
        private readonly GrammarTokenGroup _parentGroup;            // Parent group.
        private readonly GrammarSourceRange _sourceInfo;            // Source info.
        private readonly GrammarPropertyCollection _properties;     // The properties.
        private readonly GrammarCodeBlockCollection _codeBlocks;    // The code blocks.

        //-----------------------------------------------------------------------
        //     Properties
        //-----------------------------------------------------------------------

        /// <summary>Gets the name of the group.</summary>
        public GrammarTextValue Name { get { return _name; } }
        /// <summary>Gets the parent group, if any.</summary>
        public GrammarTokenGroup ParentGroup { get { return _parentGroup; } }
        /// <summary>Gets the token group source information.</summary>
        public GrammarSourceRange SourceInfo { get { return _sourceInfo; } }
        /// <summary>Gets the collection of properties.</summary>
        public GrammarPropertyCollection Properties { get { return _properties; } }
        /// <summary>Gets the collection of code blocks.</summary>
        public GrammarCodeBlockCollection CodeBlocks { get { return _codeBlocks; } }

        //-----------------------------------------------------------------------
        //     Constructors
        //-----------------------------------------------------------------------

        /// <summary>Initializes an instance of the <see cref="GrammarTokenGroup"/> class.</summary>
        /// <param name="name">The name of the group.</param>
        /// <param name="parentGroup">The parent group, if any.</param>
        /// <param name="sourceInfo">Source information.</param>
        public GrammarTokenGroup(GrammarTextValue name, GrammarTokenGroup parentGroup, GrammarSourceRange sourceInfo)
        {
            if (name.Text == null) throw new ArgumentNullException("name.Text");
            _name = name;
            _sourceInfo = sourceInfo;
            _parentGroup = parentGroup;
            _properties = new GrammarPropertyCollection();
            _codeBlocks = new GrammarCodeBlockCollection();
        }
    }
}
